// Name:                     Button Group
//
// Description:              Define style for button group
//
// Component:                `.btn-group`
//
// Modifiers:                `.btn-group-stacked`
//
//
// Uses:                     Button
//                           Icon
//
// =============================================================================

/* ==========================================================================
   Component: Button Group
 ============================================================================ */

// Make the div behave like a button
.btn-group,
.btn-group-stacked {
  position: relative;
  display: inline-block;
  vertical-align: middle; // match .#{$ns}btn alignment given font-size hack above

  > .btn {
    position: relative;
    float: left;
    // Bring the "active" button to the front
    &:hover,
    &:focus,
    &:active,
    &.active {
      z-index: 2;
    }
    &:focus {
      // Remove focus outline when dropdown JS adds it after closing the menu
      outline: 0;
    }
  }
}

// Prevent double borders when buttons are next to each other
// =============================================================================

.btn-group {
  .btn + .btn,
  .btn + .btn-group,
  .btn-group + .btn,
  .btn-group + .btn-group {
    margin-left: -1px;
  }
  // @include hook-btn-group();
}

// Optional: Group multiple button groups together for a toolbar
.btn-toolbar {
  margin-left: -5px; // Offset the first child's margin
  @include clearfix;

  .btn-group,
  .input-group {
    float: left;
  }

  > .btn,
  > .btn-group,
  > .input-group {
    margin-left: 5px;
  }
  // @include hook-btn-group-toolbar();
}

.btn-group > .btn:not(:first-child):not(:last-child):not(.#{$ns}dropdown-toggle) {
  border-radius: 0;
}

// Set corners individual because sometimes a single button can be in a .btn-group and we need :first-child and :last-child to both match
.btn-group > .btn:first-child {
  margin-left: 0;
  &:not(:last-child):not(.#{$ns}dropdown-toggle) {
    @include border-right-radius(0);
  }
}

// Need .dropdown-toggle since :last-child doesn't apply given a .dropdown-menu immediately after it
.btn-group > .btn:last-child:not(:first-child),
.btn-group > .dropdown-toggle:not(:first-child) {
  @include border-left-radius(0);
}

// Custom edits for including btn-groups within btn-groups (useful for including dropdown buttons within a btn-group)
.btn-group > .btn-group {
  float: left;
}

.btn-group > btn-group:not(:first-child):not(:last-child) > .btn {
  border-radius: 0;
}

.btn-group > .btn-group:first-child {
  > .btn:last-child,
  > .dropdown-toggle {
    @include border-right-radius(0);
  }
}

.btn-group > .btn-group:last-child > .btn:first-child {
  @include border-left-radius(0);
}

// Sizing
// =============================================================================

.btn-group-xs {
  & > .btn {
    @include button-size($btn-xs-font-size);
  }

  // @include hook-btn-group-xs();
}

.btn-group-sm {
  & > .btn {
    @include button-size($btn-sm-font-size);
  }

  // @include hook-btn-group-sm();
}

.btn-group-lg {
  & > .btn {
    @include button-size($btn-lg-font-size);
  }

  // @include hook-btn-group-lg();
}

// Stacked button group
// =============================================================================

.btn-group-stacked {
  > .btn,
  > .btn-group,
  > .btn-group > .btn {
    display: block;
    float: none;
    width: 100%;
    max-width: 100%;
  }

  // Clear floats so dropdown menus can be properly placed
  > .btn-group {
    @include clearfix;
    > .btn {
      float: none;
    }
  }

  > .btn + .btn,
  > .btn + .btn-group,
  > .btn-group + .btn,
  > .btn-group + .btn-group {
    margin-top: -1px;
    margin-left: 0;
  }
  // @include hook-btn-group-stacked();
}

.btn-group-stacked > .btn {
  &:not(:first-child):not(:last-child) {
    border-radius: 0;
  }
  &:first-child:not(:last-child) {
    border-top-right-radius: $global-radius;
    @include border-bottom-radius(0);
  }
  &:last-child:not(:first-child) {
    border-bottom-left-radius: $global-radius;
    @include border-top-radius(0);
  }
}

.btn-group-stacked > .btn-group:not(:first-child):not(:last-child) > .btn {
  border-radius: 0;
}

.btn-group-stacked > .btn-group:first-child:not(:last-child) {
  > .btn:last-child,
  > .dropdown-toggle {
    @include border-bottom-radius(0);
  }
}

.btn-group-stacked > .btn-group:last-child:not(:first-child) > .btn:first-child {
  @include border-top-radius(0);
}

// Justify button group
// =============================================================================

.btn-group-justify {
  // display: table;
  // table-layout: fixed;
  // border-collapse: separate;
  width: 100%;
  display: flex;
  > .btn,
  > .btn-group {
    float: none;
    // display: table-cell;
    // width: 1%;
    flex: 1;
  }
  > .btn-group .btn {
    width: 100%;
  }
  // @include hook-button-group-justify();
}

// Dropdown button group
// =============================================================================

.btn-group {
  .dropdown {
    float: left;
    margin-left: -1px;
    > .btn {
      @include border-left-radius(0);
    }
  }

  .active .dropdown-toggle {
    box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);

    // Show no shadow for `.btn-link` since it has no other button styles.
    &.btn-link {
      box-shadow: none;
    }
  }

  .dropdown-toggle:active,
  .active .dropdown-toggle {
    outline: 0;
  }
}

// Checkbox and radio options
// for JS Button plugin
// .#{$ns}btn-group-check added for Amaze UI react
// =============================================================================

[data-am-button] > .btn > input[type="radio"],
[data-am-button] > .btn > input[type="checkbox"],
.btn-group-check > .btn > input[type="radio"],
.btn-group-check > .btn > input[type="checkbox"] {
  position: absolute;
  z-index: -1;
  opacity: 0;
}

// Hooks
// =============================================================================

// @mixin hook-btn-group(){}
// @mixin hook-btn-group-stacked(){}
// @mixin hook-btn-group-toolbar(){}
// @mixin hook-button-group-justify(){}
// @mixin hook-btn-group-lg(){}
// @mixin hook-btn-group-sm(){}
// @mixin hook-btn-group-xs(){}
